﻿<template>
    <div>
        <el-form label-width="150px" :model="Upuser" ref="Upuser_refs">
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="角色" prop="RoleId">
                        <el-select v-model="Upuser.RoleId" required multiple class="wmax">
                            <el-option value="0" label="全部">全部</el-option>
                            <el-option v-for="(v,k) in AllRoleDB" :value="v.Id" :data-userid="v.Id" :label="v.RoleName" v-text="v.RoleName" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="员工姓名" prop="Title">
                        <el-input v-model="Upuser.UserName"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="员工性别" prop="Sex">
                        <el-radio v-model="Upuser.Sex" label="0">男</el-radio>
                        <el-radio v-model="Upuser.Sex" label="1">女</el-radio>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="身份证号码" prop="Card">
                        <el-input v-model="Upuser.Card"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="员工电话" prop="Phone">
                        <el-input v-model.number="Upuser.Phone"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="身份证地址" prop="FamilyAddress">
                        <el-input v-model="Upuser.FamilyAddress"></el-input>
                    </el-form-item>
                </el-col>

            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="员工工种" prop="JobNumber">
                        <el-input v-model="Upuser.JobNumber"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="入职时间" prop="InductionTime">
                        <el-date-picker style="width: 100%"  v-model="Upuser.InductionTime"
                                        class="wmax"
                                        type="date"
                                        placeholder="选择日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <!--<el-col :span="10" :offset="1">
            <el-form-item label="初始密码" prop="FamilyAddress">
                <el-input v-model="Upuser.Password"></el-input>
            </el-form-item>
        </el-col>-->
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="开户行" prop="BankName">
                        <el-input v-model="Upuser.BankName"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="银行卡号" prop="BankCardNumber">
                        <el-input v-model="Upuser.BankCardNumber"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="备注" prop="Remark">
                        <el-input v-model="Upuser.Remark"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="现居地" prop="NowFamilyAddress">
                        <el-input v-model="Upuser.NowFamilyAddress" placeholder="请输入现居地"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="工号" prop="UserNumber">
                        <el-input v-model="Upuser.UserNumber"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <h2>身份证</h2>
                    <el-form-item label="身份证" prop="PostLevel">
                        <UploadFileF ref="AnotherData"
                                     :multiple="true"
                                     :another-data="AnotherData"
                                     :showfilelist="true"
                                     :upshow="false"
                                     content="点击上传身份证"
                                     btnsize="medium"></UploadFileF>
                    </el-form-item>
                </el-col>
               <el-col :span="10" :offset="1">
                    <h2>银行卡</h2>
                    <el-form-item label="银行卡" prop="PostLevel">
                        <UploadFileF ref="AnotherData2"
                                     :multiple="true"
                                     :another-data="AnotherData2"
                                     :showfilelist="true"
                                     :upshow="false"
                                     content="点击上传银行卡"
                                     btnsize="medium"></UploadFileF>
                    </el-form-item>
<!-- 					<el-form-item label="银行卡2" prop="PostLevel">
					    <UploadFileF ref="AnotherData3"
					                 :multiple="false"
					                 :another-data="AnotherData3"
					                 :showfilelist="true"
					                 :upshow="false"
					                 content="点击上传银行卡"
					                 btnsize="medium"></UploadFileF>
					</el-form-item> -->
                </el-col>
            </el-row>

            <el-row>
                <el-col align="center">
                    <el-button type="success" @click="UpuserSave">修改信息</el-button>
                    <el-button type="success" @click="Upuserreset">重置</el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>
<script>
    import * as publicjs from "/public/Scriput/Public"
    import UploadFileF from "../UploadFileF";
    export default {
        components: {
            UploadFileF,
        },
        props: {
            AllRoleDB: {
                type: Array,
                required: true
            },
            Upuser: {
                type: Object,
                required: true
            },
        },
        name: "Upuser",
        data() {
            return {
                rules: {
                    name: [
                        { required: true, message: '请输入用户名称', trigger: 'blur' },
                    ],
                    phone: [
                        { required: true, message: '请输入电话号码', trigger: 'blur' },
                        { min: 11, max: 11, message: '请输入正确的电话号码', trigger: 'blur' }
                    ],
                    UserNumber: [
                         { required: true, message: '请填写正确的工号不能为空', trigger: 'blur' }, 
                    ],
                },
                //文件上传参数
                AnotherData: {
                    FileType: 1,
                    id: 0,
                    Type: 1,
                    Single: false,
                },
                AnotherData2: {
                    FileType: 1,
                    id: this.Upuser.Id,
                    Type: 2,
                    Single: false,
                },
				AnotherData3: {
				    FileType: 1,
				    id: this.Upuser.Id,
				    Type: 3,
				    Single: false,
				},
            }
        },
        watch: {
            Upuser: function (val) {
                this.init();
            }
        },
        created() {
            this.init();
        },
        methods: {
            UpuserSave() {
				this.AnotherData.id = this.Upuser.Id
				this.AnotherData2.id = this.Upuser.Id
				this.AnotherData3.id = this.Upuser.Id
                this.Upuser.RoleId = this.Upuser.RoleId.join(',');
                //this.Upuser.UserPosition = this.Upuser.UserPosition.join(',');
                let loadding = this.openLoading();
                this.$http.post("UserInfo/UpdateUsersContent", { users: this.Upuser })
                    .then(res => {
                        loadding.close();
                        if (res.data.flag) {
                            this.$message.success("修改成功")
                            if (this.$refs['AnotherData'].fileList.length > 0) {
                                //this.AnotherData.Type = this.Upuser.Id;
                                this.$refs['AnotherData'].submitUpload()
                            }
                            if (this.$refs['AnotherData2'].fileList.length > 0) {
                                //this.AnotherData2.Type = this.Upuser.Id;
                                this.$refs['AnotherData2'].submitUpload()
                            }
							// if (this.$refs['AnotherData3'].fileList.length > 0) {
							//     //this.AnotherData2.Type = this.Upuser.Id;
							//     this.$refs['AnotherData3'].submitUpload()
							// }
                            this.$parent.$parent.UpUserShow = false;
                            this.$parent.$parent.GettableDB();
                        } else {
                            this.$message.error("修改失败")
                        }
                    });
            },
            Upuserreset() {
                this.$refs["Upuser_refs"].resetFields();
            },
            arraytostr(str) {
                if (str !== null && str !== undefined) {
                    let arr = [];
                    let starray = str.split(",")
                    starray.forEach(function (item, index) {
                        let iid = parseInt(item);
                        arr.push(iid);
                    })
                    return arr;
                }

            },
            init() {
                this.Upuser.RoleId = this.Upuser.RoleId !== "NaN" ? this.arraytostr(this.Upuser.RoleId) : [];
                this.Upuser.InternshipState = this.Upuser.InternshipState.toString();
                this.Upuser.Sex = (this.Upuser.Sex.toString());
                this.$refs['AnotherData'].fileList = [];
                this.$refs['AnotherData2'].fileList = [];
            },
        },
    }
</script>
<style scoped>
    .wmax {
        width: 100%;
    }
</style>
